package com.itheima.service.impl;

import com.itheima.mapper.ClassMapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private ClassMapper classMapper;

    @Override
    public Map<String, List<Object>> queryJobCount() {
        //查询不同岗位的员工数量
        List<Map<String, Object>> mapList = empMapper.queryJobCount();
        //完成数据封装
        List<Object> jobList = mapList.stream().map(map -> map.get("jobName").toString()).collect(Collectors.toList());
        List<Object> dataList = mapList.stream().map(map -> Integer.parseInt(map.get("count").toString())).collect(Collectors.toList());
//        HashMap<String,List<Object>> hashMap=new HashMap<>();
//        hashMap.put("jobList",jobList);
//        hashMap.put("dataList",dataList);

        return Map.of("jobList",jobList,"dataList",dataList);
    }

    @Override
    public List<Map<String, Object>> queryGenderCount() {
        List<Map<String, Object>> genderCount = empMapper.queryGenderCount();
        List<Map<String, Object>> mapList = genderCount.stream().map(map -> Map.of("name", map.get("gender"), "value", map.get("count"))).collect(Collectors.toList());
        return mapList;
    }

    @Override
    public Map<String, List<Object>> queryClazzCount() {
        List<Map<String,Object>> mapList=classMapper.queryClazzCount();
        List<Object> clazzList = mapList.stream().map(map -> map.get("cname").toString()).collect(Collectors.toList());
        List<Object> dataList = mapList.stream().map(map -> Integer.parseInt(map.get("count").toString())).collect(Collectors.toList());
        return Map.of("clazzList",clazzList,"dataList",dataList);
    }

    @Override
    public List<Map<String, Object>> queryDegreeData() {
        List<Map<String,Object>> degreeCount=classMapper.queryDegreeData();
        List<Map<String, Object>> mapList = degreeCount.stream().map(map -> Map.of("name", map.get("degree"), "value", map.get("count"))).collect(Collectors.toList());
        return mapList;
    }
}
